var { mysql } = require('../qcloud')

// 判断用户是否注册
module.exports = async (ctx, next) => {
    try {
        if (String.isNotBlank((ctx.query || {}).openid)) {
            let res = await mysql('cMemberInfo').count('cid as count').where({ openid: ctx.query.openid })
            if (Array.isArray(res) && res.length > 0) {
                ctx.state.data = res[0].count
                ctx.state.code = 200
            } else {
                ctx.state.data = 'query fail or data is null'
                ctx.state.code = 204
            }
        } else {
            ctx.state.data = 'openid is not exist'
            ctx.state.code = 204
        }
    } catch (error) {
        ctx.state.data = error
        ctx.state.code = 409
    }
}
